package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.pojo.Item;
import com.jt.vo.EasyUITable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jt.mapper.ItemMapper;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {
	
	@Autowired
	private ItemMapper itemMapper;

//	@Override
//	public EasyUITable findItemByPage(int page, int rows) {
//		//1.total  获取数据库总记录数
//		long total = itemMapper.selectCount(null);
//		//2.rows   商品分页查询的结果
//		int startNum = (page-1)*rows;
//		List<Item> itemByPage = itemMapper.findItemByPage(startNum, rows);
//		//3.将返回值结果封装
//		return new EasyUITable(total,itemByPage);
//	}
	@Override
	public EasyUITable findItemByPage(int page, int rows) {
		//利用MybatisPlus方式分页，使用iPage对象封装分页信息
		IPage<Item> iPage = new Page<>(page,rows);
		QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByDesc("updated");
		iPage = itemMapper.selectPage(iPage, queryWrapper);
		return new EasyUITable(iPage.getTotal(),iPage.getRecords());
	}
}
